package com.vito.demo.sb1.web

import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import java.util.*

/**
 * Created by lingzhiyuan.
 * Date : 16/3/31.
 * Time : 下午3:13.
 * Description:
 *
 */

@RestController
class UserController {
    @RequestMapping("/users")
    fun returnUser(@RequestParam(required = false, defaultValue =
    "3") index: Int): HashMap<Any, Any?> {

        val users = HashMap<Any, Any?>()

        try {
            if (index > 100) {
                throw Exception("number too large")
            }
            for (i in 0 .. index - 1) {
                users.put(i, "number : " + i)
            }
        }
        catch (e: Exception) {
            users.put("errorMessage", e.message)
        }

        return users
    }
}

